@extends('Admin.layout.layout')

@section('title')
	<title>栏目列表</title>
@endsection

@section('con')
<div class="row"> 
   <div class="col-lg-12"> 
    <h1 class="page-header">栏目列表</h1> 
   </div> 
   <!-- /.col-lg-12 --> 
  </div> 
 <div class="row"> 
   <div class="col-lg-12"> 
    <div class="panel panel-default"> 
     <div class="panel-heading">
       
     </div> 
     
     <!-- /.panel-heading --> 
     <div class="panel-body"> 
      <div class="dataTable_wrapper"> 
       <div id="dataTables-example_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
       <form action="{{url('/admin/type/index')}}"" method="get">
        <div class="row">
         <div class="col-sm-6">
          <div class="dataTables_length" id="dataTables-example_length">
           <label>显示 <select name="num" aria-controls="dataTables-example" class="form-control input-sm">
           <option value="5" @if(!empty($data['num']) && $data['num'] == 5){ selected }@endif>5</option>
           <option value="10" @if(!empty($data['num']) && $data['num'] == 10){ selected }@endif>10</option>
           <option value="15" @if(!empty($data['num']) && $data['num'] == 15){ selected }@endif>15</option>
           <option value="20" @if(!empty($data['num']) && $data['num'] == 20){ selected }@endif>20</option>
           </select> 条</label>
          </div>
         </div>
         <div class="col-sm-6">
          <div id="dataTables-example_filter" class="dataTables_filter">
           <label>查询:<input type="search"  name="keywords"  value="{{$data['keywords'] or ''}}" class="form-control input-sm" placeholder="请输入栏目名称" aria-controls="dataTables-example" /></label>
           <button class="btn btn-outline btn-default btn-sm" type="submit">搜索</button>
          </div>
         </div>
        </div>
        </form>
        <div class="row">
         <div class="col-sm-12">
          <table id="dataTables-example" class="table table-striped table-bordered table-hover dataTable no-footer" role="grid" aria-describedby="dataTables-example_info"> 
           <thead> 
            <tr role="row">
             <th class="sorting_asc" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 55px;" aria-sort="ascending" aria-label="Rendering engine: activate to sort column descending">ID</th>
             <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 170px;" aria-label="Browser: activate to sort column ascending">栏目名称</th>
             <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 184px;" aria-label="Platform(s): activate to sort column ascending">所属栏目</th>
             <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 150px;" aria-label="Engine version: activate to sort column ascending">path</th>
             <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 150px;" aria-label="Engine version: activate to sort column ascending">是否显示</th>
             <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 108px;" aria-label="CSS grade: activate to sort column ascending">操作</th>
             <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 120px;" aria-label="Engine version: activate to sort column ascending">前台是否显示</th>
             <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 180px;" aria-label="CSS grade: activate to sort column ascending">操作</th>
            </tr> 
           </thead>
        
           <tbody>
           @foreach($cates as $k =>$v) 
            <tr class="gradeA odd" role="row"> 
             <td class="sorting_1" id="lid">{{$v->id}}</td> 
             <td class="sorting_1">{{$v->name}}</td> 
             @if($v->pid == 0)
             <td class="sorting_1">顶级栏目</td>
             @elseif($v->pid != 0) 
             <td class="sorting_1">所属栏目———— <b>{{$v->pname}}</b></td>
			 @endif
             <td class="sorting_1">{{$v->path}}</td>
             @if($v->status == 1)
             <td class="sorting_1">是</td> 
             @elseif($v->status == 0)
             <td class="sorting_1">否</td> 
             @endif
             <td class="sorting_1">
			<button class="btn btn-danger btn-xs btn-delete" >删除</button>
			<a href="{{url('/admin/type/edit',['id'=>$v->id])}}" class="btn btn-info btn-xs" >修改</a></td> 
             <td class="sorting_1">显示</td> 
             @elseif($v->status == 0)
             <td class="sorting_1">未显示</td> 
             @endif
             <td class="sorting_1">
			<button class="btn btn-danger btn-xs btn-delete" >删除</button>
      <a href="{{url('/admin/type/edit',['id'=>$v->id])}}" class="btn btn-info btn-xs" >修改</a>
			<a href="{{url('/admin/type/change',['id'=>$v->id])}}" class="btn btn-info btn-xs" >修改显示状态</a></td> 
            </tr>
        	@endforeach
           </tbody> 
          </table>
         </div>
        </div>
        <div class="row">
         <div class="col-sm-6">
          <div class="dataTables_info" id="dataTables-example_info" role="status" aria-live="polite">
          </div>
          
         </div>
         <div class="col-sm-6">
          <div class="dataTables_paginate paging_simple_numbers" id="dataTables-example_paginate">
           {!! $cates->appends($data)->render() !!}
          </div>
         </div>
        </div>
       </div> 
      </div> 
      <!-- /.table-responsive --> 
      
     </div> 
     <!-- /.panel-body --> 
    </div> 
    <!-- /.panel --> 
   </div> 
   <!-- /.col-lg-12 --> 
  </div>

@endsection

@section('js')
	
	<script type="text/javascript">
	// alert($);
	$.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
    });

    $('.btn-delete').click(function(){

    	var id = $(this).parents('tr').find('#lid').text();
    	var btn = $(this);
    
    	$.post('{{url("/admin/type/del")}}',{id:id},function(data){

		if(data == 1){
			btn.parents('tr').remove();
		}else{
			alert('有下属栏目,不可删除');
		}
	});


    })

	</script>
@endsection
